1
0

add-goods.vue 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991
  1. <template>
  2. <app-layout>
  3. <scroll-view scroll-y :style="{'height':`${windowHeight}px`}">
  4. <view class='title'>基本信息</view>
  5. <!-- 商品类型 fjt -->
  6. <view class='goods-type' v-if="is_ecard === 1">
  7. <view class='info-item type cross-center dir-left-nowrap'>
  8. <view class="form-label">商品类型</view>
  9. <view class="select">
  10. <radio-group @change="typeChange" class="dir-left-nowrap main-between">
  11. <label class="dir-left-nowrap">
  12. <view>
  13. <radio :disabled="id !== 0" color="#446dfd" value="goods" :checked="form.type === 'goods'"/>
  14. </view>
  15. <view class="select-label">实体商品</view>
  16. </label>
  17. <label class="dir-left-nowrap">
  18. <view>
  19. <radio :disabled="id !== 0" color="#446dfd" value="ecard" :checked="form.type === 'ecard'"/>
  20. </view>
  21. <view class="select-label" >电子卡密</view>
  22. </label>
  23. </radio-group>
  24. </view>
  25. </view>
  26. <view class='info-item cross-center main-between' v-if="form.type === 'ecard'">
  27. <view class="form-label">选择卡密</view>
  28. <view @click="chooseECard">
  29. <view class='cat-info dir-right-nowrap cross-center'>
  30. <view class='cat-info dir-right-nowrap cross-center'>
  31. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  32. <text v-if="form.plugin_data.ecard.ecard_id > 0">{{form.plugin_data.ecard.name}}</text>
  33. <text style="color: #cdcdcd" v-else>未选择</text>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class='goods-img'>
  40. <view class='label'>
  41. <text style="color: #353535">商品图片</text>
  42. <text class="label-info">(最多9张,可拖拽改变顺序)</text>
  43. </view>
  44. <view class='goods-list'>
  45. <movable-area style="height: auto; width: 100%;" class="flex-wrap">
  46. <view
  47. @touchend.stop='touchend'
  48. @touchmove.stop='touchm'
  49. @longpress.stop='_longtap(item.pic_url,index,$event)'
  50. class='goods-item'
  51. v-for="(item,index) in img"
  52. :key="index"
  53. >
  54. <image
  55. mode="aspectFill"
  56. class='goods-cover move-img'
  57. :data-index="index"
  58. :src="item.pic_url"
  59. ></image>
  60. <image
  61. @click.stop='del_img(index)'
  62. v-if="!beMove"
  63. class='del-btn'
  64. src='./../image/delete.png'
  65. ></image>
  66. <view v-if="index === 0 && !beMove" class='main-img'>主图</view>
  67. </view>
  68. <view v-if="img.length < 9" @click.stop='addImg' class='add-goods-img'>
  69. <image src='./../image/add-goods.png'></image>
  70. <view>添加</view>
  71. </view>
  72. <movable-view :data-index="beginIndex" :x="x" :y="y" direction="all" :damping="5000" :friction="1" :disabled="disabled">
  73. <image :hidden='imgHidden' mode="aspectFill" class="goods-cover img-border" :src='img_src'></image>
  74. </movable-view>
  75. </movable-area>
  76. </view>
  77. </view>
  78. <view class='goods-info'>
  79. <view class='info-item goods-name cross-center dir-left-nowrap'>
  80. <view class="form-label">商品名称</view>
  81. <view @click="nameBlur" v-if="inputName" :class="form.name.length > 0 ? 'input' : 'input placeholder'">{{form.name ? form.name :'请输入商品名称'}}</view>
  82. <input :focus="!inputName" @blur="nameBlur" v-else class='input' placeholder-style="color: #cdcdcd" placeholder="请输入商品名称" v-model='form.name'/>
  83. </view>
  84. <view class='info-item cross-center main-between'>
  85. <view class="form-label">商品分类</view>
  86. <view @click="chooseCat">
  87. <view class='cat-info dir-right-nowrap cross-center'>
  88. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  89. <text v-if="cats.length > 0">编辑</text>
  90. <text style="color: #cdcdcd" v-else>未选择</text>
  91. </view>
  92. </view>
  93. </view>
  94. <view class='info-item cross-center dir-left-nowrap'>
  95. <view class="form-label">单位</view>
  96. <view class='dir-left-nowrap cross-center'>
  97. <input maxlength="4" placeholder-style="color: #cdcdcd" placeholder="请输入商品单位" v-model='unit' class='input'/>
  98. </view>
  99. </view>
  100. </view>
  101. <view class='title'>{{form.type === 'goods' ? '规格、价格及' : '价格、'}}库存</view>
  102. <view class='goods-info'>
  103. <view class='info-item main-between' v-if="form.type === 'goods'">
  104. <view>多规格</view>
  105. <switch style="transform:scale(0.7)" :checked="set_attr" @change="set_attr = !set_attr"></switch>
  106. </view>
  107. <view v-if="set_attr && form.type === 'goods'" class='info-item cross-center main-between'>
  108. <view class="form-label">商品规格</view>
  109. <view @click="chooseAttr">
  110. <view class='cat-info dir-right-nowrap cross-center'>
  111. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  112. <text v-if="attr">已设置</text>
  113. <text style="color: #cdcdcd" v-else>未设置,点击设置</text>
  114. </view>
  115. </view>
  116. </view>
  117. <view v-if="!set_attr && form.type === 'goods'" class='info-item cross-center dir-left-nowrap'>
  118. <view class="form-label">规格</view>
  119. <view class='dir-left-nowrap cross-center price-input'>
  120. <input class='input' placeholder-style="color: #cdcdcd" v-model='form.attr_default_name'></input>
  121. </view>
  122. </view>
  123. <view class='info-item cross-center dir-left-nowrap'>
  124. <view class="form-label">成本价</view>
  125. <view class='dir-left-nowrap price-input cross-center main-between'>
  126. <input @change="costChange" placeholder-style="color: #cdcdcd" placeholder="请输入成本价" type='digit' class='input' v-model="form.cost_price"></input>
  127. <view>元</view>
  128. </view>
  129. </view>
  130. <view class='info-item cross-center dir-left-nowrap'>
  131. <view class="form-label">原价</view>
  132. <view class='dir-left-nowrap price-input cross-center main-between'>
  133. <input @change="originalChange" placeholder-style="color: #cdcdcd" placeholder="请输入原价" type='digit' class='input' v-model="form.original_price"></input>
  134. <view>元</view>
  135. </view>
  136. </view>
  137. <view class='info-item cross-center dir-left-nowrap'>
  138. <view class="form-label">售价</view>
  139. <view class='dir-left-nowrap price-input cross-center main-between'>
  140. <input @change="priceChange" placeholder-style="color: #cdcdcd" placeholder="请输入售价" type='digit' class='input' v-model="form.price"></input>
  141. <view>元</view>
  142. </view>
  143. </view>
  144. <view v-if="!set_attr" class='info-item cross-center dir-left-nowrap'>
  145. <view class="form-label">库存</view>
  146. <view class='dir-left-nowrap price-input cross-center main-between'>
  147. <input placeholder-style="color: #cdcdcd" placeholder="请输入库存" type='number' v-model="form.goods_num" class='input unit'></input>
  148. <view class="unit-width">{{unit}}</view>
  149. </view>
  150. </view>
  151. <view v-if="!set_attr" class='info-item cross-center dir-left-nowrap'>
  152. <view class="form-label">货号</view>
  153. <view class='dir-left-nowrap price-input cross-center'>
  154. <input placeholder-style="color: #cdcdcd" placeholder="请输入货号" class='input' v-model="form.goods_no"></input>
  155. </view>
  156. </view>
  157. <view v-if="!set_attr && form.type === 'goods'" class='info-item cross-center dir-left-nowrap'>
  158. <view class="form-label">重量</view>
  159. <view class='dir-left-nowrap cross-center price-input'>
  160. <input placeholder-style="color: #cdcdcd" placeholder="请输入重量" type='number' v-model='form.goods_weight' class='input'></input>
  161. <view>g</view>
  162. </view>
  163. </view>
  164. </view>
  165. <view class='title'>{{form.type === 'goods' ? '运费、包邮及' : ''}}限购</view>
  166. <view class='goods-info'>
  167. <view class='info-item cross-center main-between' v-if="form.type === 'goods'">
  168. <view class="form-label">运费设置</view>
  169. <view @click="chooseExpress">
  170. <view class='cat-info dir-right-nowrap cross-center'>
  171. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  172. <text v-if="bePostage.id > -1">{{bePostage.name}}</text>
  173. <text style="color: #cdcdcd" v-else>未选择</text>
  174. </view>
  175. </view>
  176. </view>
  177. <view class='info-item cross-center main-between' v-if="form.type === 'goods'">
  178. <view class="form-label">包邮规则</view>
  179. <view @click="chooseDelivery">
  180. <view class='cat-info dir-right-nowrap cross-center'>
  181. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  182. <text v-if="beDelivery.id > -1">{{beDelivery.name}}</text>
  183. <text style="color: #cdcdcd" v-else>未选择</text>
  184. </view>
  185. </view>
  186. </view>
  187. <view class='info-item main-between'>
  188. <view>限购</view>
  189. <switch style="transform:scale(0.7)" :checked="confine" @change="changeConfine"></switch>
  190. </view>
  191. <view v-if="confine" class='info-item cross-center dir-left-nowrap'>
  192. <view class="form-label">限购数量</view>
  193. <view class='dir-left-nowrap cross-center price-input'>
  194. <view class='dir-left-nowrap cross-center price-input'>
  195. <input placeholder-style="color: #cdcdcd" style="width:396rpx;" placeholder="请输入限购数量" type='number' v-model='form.confine_count' class='input'></input>
  196. <view>{{unit}}</view>
  197. </view>
  198. </view>
  199. </view>
  200. </view>
  201. <view class='title'>商品图文描述</view>
  202. <view class='goods-info'>
  203. <view class='info-item cross-center main-between'>
  204. <view class="form-label">商品图文描述</view>
  205. <view @click="toGoodsDetail">
  206. <view class='cat-info dir-right-nowrap cross-center'>
  207. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  208. <text v-if="goods_detail.length > 0">已添加</text>
  209. <text style="color: #cdcdcd" v-else>未添加</text>
  210. </view>
  211. </view>
  212. </view>
  213. </view>
  214. <view class='title'>积分设置</view>
  215. <view class='goods-info integral-info'>
  216. <view class='express-setting'>
  217. <view class='express-input cross-center'>
  218. <view class="integral">积分赠送</view>
  219. <input placeholder-style="color: #cdcdcd" placeholder="请输入积分赠送数量或比例" v-model='give_integral' class='input'></input>
  220. </view>
  221. <view class='express-etc'>会员购物赠送积分,如果不填或填0,则默认为不赠送,如果带%则为按成交价格的比例计算积分。</view>
  222. </view>
  223. <view class='express-setting'>
  224. <view class='express-input cross-center'>
  225. <view class="integral">积分抵扣</view>
  226. <input placeholder-style="color: #cdcdcd" placeholder="请输入积分抵扣数量或比例" v-model='forehead_integral' class='input'></input>
  227. </view>
  228. <view class='express-etc'>如果不填或填0,则不支持积分抵扣;如果带%则为按成交价格的比例计算抵扣多少元。</view>
  229. </view>
  230. </view>
  231. <view class='title'>卡券</view>
  232. <view class='goods-info'>
  233. <view class='info-item cross-center main-between'>
  234. <view class="form-label">卡券</view>
  235. <view @click="chooseCard">
  236. <view class='cat-info dir-right-nowrap cross-center'>
  237. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  238. <text class="service-text" v-if="goods_card.length > 0">
  239. <text v-for="(item,index) in goods_card" :key="index">
  240. <text v-if="index > 0">,</text>
  241. {{item.name}}
  242. </text>
  243. </text>
  244. <text style="color: #cdcdcd" v-else>未选择</text>
  245. </view>
  246. </view>
  247. </view>
  248. </view>
  249. <view class='title'>服务内容</view>
  250. <view class='goods-info'>
  251. <view class='info-item main-between'>
  252. <view>默认服务</view>
  253. <switch style="transform:scale(0.7)" :checked="is_default_services" @change="is_default_services=!is_default_services"></switch>
  254. </view>
  255. <view v-if="is_default_services == 0" class='info-item cross-center main-between'>
  256. <view class="form-label">服务内容</view>
  257. <view @click="chooseService">
  258. <view class='cat-info dir-right-nowrap cross-center'>
  259. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  260. <text class="service-text" v-if="beService.length > 0">
  261. <text v-for="(item,index) in beService" :key="index">
  262. <text v-if="index > 0">,</text>
  263. {{item.name}}
  264. </text>
  265. </text>
  266. <text style="color: #cdcdcd" v-else-if="service.length > 0">未选择</text>
  267. <text style="color: #cdcdcd" v-else>未设置</text>
  268. </view>
  269. </view>
  270. </view>
  271. </view>
  272. <view class="main-between form-button">
  273. <view @click="submit(0)">
  274. <view class='save'>保存</view>
  275. </view>
  276. <view @click="submit(1)">
  277. <view class='send'>上架</view>
  278. </view>
  279. </view>
  280. <view :class="['dialog', `${iphone_x?'iphone_x':''}`]" v-if="dialog">
  281. <view class="picker-list">
  282. <view class="main-between picker-header">
  283. <view @click="toggle">取消</view>
  284. <view @click="toggle(1)">确定</view>
  285. </view>
  286. <picker-view v-if="dialogType == 'postage'" :value="[set_postage?postageIndex:-1]" class="picker" @change="bindChange">
  287. <picker-view-column>
  288. <view v-for="(item,idx) in postage" :key="item.id"
  289. :class="[`cross-center picker-text`,{
  290. 'sure-color': newIndex === idx,
  291. 'cardinal-color': newIndex === idx + 1 || newIndex === idx - 1,
  292. 'even-color': newIndex === idx + 2 || newIndex === idx - 2,
  293. }]">{{item.name}}</view>
  294. </picker-view-column>
  295. </picker-view>
  296. <picker-view v-if="dialogType == 'delivery'" :value="[set_delivery?deliveryIndex:-1]" class="picker" @change="bindChange">
  297. <picker-view-column>
  298. <view v-for="(item,idx) in delivery" :key="item.id"
  299. :class="[`cross-center picker-text`,{
  300. 'sure-color': newIndex === idx,
  301. 'cardinal-color': newIndex === idx + 1 || newIndex === idx - 1,
  302. 'even-color': newIndex === idx + 2 || newIndex === idx - 2,
  303. }]">{{item.name}}</view>
  304. </picker-view-column>
  305. </picker-view>
  306. </view>
  307. </view>
  308. <view :class="['dialog', `${iphone_x?'iphone_x':''}`]" v-if="ecard_dialog">
  309. <view class="picker-list">
  310. <view class="main-between picker-header">
  311. <view @click="ecardToggle">取消</view>
  312. <view @click="ecardToggle(1)">确定</view>
  313. </view>
  314. <picker-view :value="[ecard_set_postage?ecard_postageIndex:-1]" class="picker" @change="bindChange">
  315. <picker-view-column>
  316. <view v-for="(item,idx) in ecard_postage" :key="item.id"
  317. :class="[`cross-center picker-text`,{
  318. 'sure-color': newIndex === idx,
  319. 'cardinal-color': newIndex === idx + 1 || newIndex === idx - 1,
  320. 'even-color': newIndex === idx + 2 || newIndex === idx - 2,
  321. }]">{{item.name}}</view>
  322. </picker-view-column>
  323. </picker-view>
  324. </view>
  325. </view>
  326. </scroll-view>
  327. <view class='dialog' v-if="is_service">
  328. <view class='dialog-item'>
  329. <view class='dialog-title'>服务内容</view>
  330. <view class="type-list">
  331. <view v-if="is_service" v-for="(item,index) in service" :key="index" @click='choose(item)' class="dir-left-nowrap type-choose" >
  332. <image v-if="item.isChoose" class="active-status" src='./../image/active.png'></image>
  333. <image v-else class="active-status" src='/static/image/icon/form-er.png'></image>
  334. <view :class="[`${item.isChoose ? 'active':''}`]">{{item.name}}</view>
  335. </view>
  336. </view>
  337. <view class="main-center btn-area">
  338. <view class="submit-btn" @click='cancelService'>取消</view>
  339. <view class="line"></view>
  340. <view class="submit-btn be-submit" @click='submitService'>确认</view>
  341. </view>
  342. </view>
  343. </view>
  344. <view class='dialog' v-if="modal">
  345. <view class='dialog-item'>
  346. <view class='dialog-title'>提示</view>
  347. <view class="error-info" v-if="set_cat">您暂未设置分类</view>
  348. <view class="error-info" v-if="set_postage && postage.length == 0">您暂未设置运费模板</view>
  349. <view class="error-info" v-if="set_delivery && delivery.length == 0">您暂未设置包邮规则</view>
  350. <view class="error-info" v-if="set_service && service.length == 0">您暂未设置服务内容</view>
  351. <view class="error-info" v-if="set_card && card.length == 0">您暂未设置卡券</view>
  352. <view class="error-info">请前往商城后台设置</view>
  353. <view class="main-center btn-area">
  354. <view class="submit-btn be-submit" @click='close'>确认</view>
  355. </view>
  356. </view>
  357. </view>
  358. <view class='dialog' v-if="error">
  359. <view class='dialog-item'>
  360. <view class='dialog-title'>提示</view>
  361. <view class="error-info">{{error}}</view>
  362. <view class="main-center btn-area">
  363. <view class="submit-btn be-submit" @click='close'>确认</view>
  364. </view>
  365. </view>
  366. </view>
  367. <view class='dialog' v-if="beSubmit">
  368. <view class='dialog-item'>
  369. <view class='dialog-title'>提示</view>
  370. <view class="submit-info">是否确认要上架此商品</view>
  371. <view class="main-center btn-area">
  372. <view class="submit-btn" @click='close'>取消</view>
  373. <view class="line"></view>
  374. <view class="submit-btn be-submit" @click='toSubmit'>确认</view>
  375. </view>
  376. </view>
  377. </view>
  378. </app-layout>
  379. </template>
  380. <script>
  381. import { mapState } from "vuex";
  382. import uploadFile from '../../../core/upload.js';
  383. export default {
  384. data() {
  385. return {
  386. postageIndex: -1,
  387. deliveryIndex: -1,
  388. height: 0,
  389. give_integral: 0,
  390. forehead_integral: 0,
  391. windowHeight: 0,
  392. beSubmit: false,
  393. inputName: true,
  394. form: {
  395. cats: [],
  396. name: '',
  397. cost_price: '',
  398. price: '',
  399. original_price: '',
  400. type: 'goods',
  401. plugin_data: {
  402. ecard: {
  403. ecard_id: 0
  404. }
  405. },
  406. attr_default_name: '默认规格'
  407. },
  408. cats: [],
  409. forehead: -1,
  410. unit: '件',
  411. iphone_x: false,
  412. set_attr: false,
  413. is_default_services: true,
  414. modal: false,
  415. error: false,
  416. set_cat: false,
  417. set_postage: false,
  418. set_delivery: false,
  419. set_service: false,
  420. set_card: false,
  421. confine: false,
  422. is_service: false,
  423. goods_card: [],
  424. img: [],
  425. card: [],
  426. goods_detail: [],
  427. beMove: false,
  428. service: [],
  429. postage: [],
  430. delivery: [],
  431. bePostage: '',
  432. beDelivery: '',
  433. beService: [],
  434. default_service: [],
  435. newIndex: '0',
  436. index: '0',
  437. attr: false,
  438. have_children: false,
  439. disabled: true,
  440. imgHidden: true,
  441. flag: false,
  442. x: 0,
  443. y: 0,
  444. id: 0,
  445. first_service: true,
  446. choose_list: [],
  447. elements: [],
  448. img_src: '',
  449. dialog: false,
  450. loading: false,
  451. ecard_dialog: false,
  452. is_ecard: 0,
  453. ecard_api_url: '',
  454. ecardBePostage: '',
  455. ecard_postage: [],
  456. ecard_set_postage: false,
  457. ecard_postageIndex: -1,
  458. beginIndex: null,
  459. dialogType: '',
  460. }
  461. },
  462. computed: {
  463. ...mapState({
  464. userInfo: state => state.user.info,
  465. adminImg: state => state.mallConfig.__wxapp_img.app_admin,
  466. })
  467. },
  468. methods: {
  469. changeConfine() {
  470. this.confine = !this.confine
  471. if(this.confine && this.form.confine_count == -1) {
  472. this.form.confine_count = ''
  473. }
  474. },
  475. money(val) {
  476. let num = val.toString(); //先转换成字符串类型
  477. if (num.indexOf('.') == 0) { //第一位就是 .
  478. num = '0' + num
  479. }
  480. num = num.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
  481. num = num.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
  482. num = num.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  483. num = num.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
  484. if (num.indexOf(".") < 0 && num != "") {
  485. num = parseFloat(num);
  486. }
  487. return +num
  488. },
  489. costChange(e) {
  490. this.form.cost_price = this.money(e.detail.value)
  491. },
  492. originalChange(e) {
  493. this.form.original_price = this.money(e.detail.value)
  494. },
  495. priceChange(e) {
  496. this.form.price = this.money(e.detail.value)
  497. },
  498. nameBlur() {
  499. this.inputName = !this.inputName;
  500. },
  501. catchTouchMove() {
  502. return false;
  503. },
  504. toSubmit() {
  505. let that = this;
  506. if(that.loading) {
  507. return false
  508. }
  509. uni.showLoading({
  510. title: '提交中...'
  511. });
  512. that.loading = true;
  513. that.beSubmit = false;
  514. that.$request({
  515. url: that.$api.app_admin.edit,
  516. data: {
  517. form: JSON.stringify(that.form),
  518. attrGroups: JSON.stringify(that.form.attr_groups)
  519. },
  520. method: 'post'
  521. }).then(response=>{
  522. that.loading = false;
  523. that.$hideLoading();
  524. uni.hideLoading();
  525. that.loading = false;
  526. if(response.code == 0) {
  527. if(response.code == 0) {
  528. uni.showToast({
  529. title: response.msg,
  530. duration: 1000
  531. });
  532. setTimeout(function() {
  533. uni.navigateBack();
  534. }, 500)
  535. }else {
  536. uni.showToast({
  537. title: response.msg,
  538. icon: 'none',
  539. duration: 1000
  540. });
  541. }
  542. }else {
  543. uni.showToast({
  544. title: response.msg,
  545. icon: 'none',
  546. duration: 1000
  547. });
  548. }
  549. }).catch(response => {
  550. that.loading = false;
  551. that.$hideLoading();
  552. uni.hideLoading();
  553. });
  554. },
  555. submit(status) {
  556. let pass = false;
  557. let that = this;
  558. let form = that.form;
  559. let cats = [];
  560. if (that.img.length > 0) {
  561. form.pic_url = that.img;
  562. } else {
  563. that.error = '请上传商品图片';
  564. return false
  565. }
  566. if (!form.name) {
  567. that.error = '请设置商品名称';
  568. return false
  569. }
  570. if (that.cats.length == 0) {
  571. that.error = '请设置商品分类';
  572. return false
  573. }else {
  574. for(let i in that.cats) {
  575. cats.push(that.cats[i].value)
  576. }
  577. }
  578. if (!that.unit) {
  579. that.error = '请设置商品单位';
  580. return false
  581. } else {
  582. form.unit = that.unit
  583. }
  584. if (form.cost_price != 0 && !form.cost_price) {
  585. that.error = '请设置商品成本价';
  586. return false
  587. }
  588. if (form.cost_price < 0) {
  589. that.error = '成本价不得小于零';
  590. return false
  591. }
  592. if (form.original_price != 0 && !form.original_price) {
  593. that.error = '请设置商品原价';
  594. return false
  595. }
  596. if (form.original_price < 0) {
  597. that.error = '商品原价不得小于零';
  598. return false
  599. }
  600. if (form.price != 0 && !form.price) {
  601. that.error = '请设置商品售价';
  602. return false
  603. }
  604. if(!that.set_attr) {
  605. form.use_attr = 0;
  606. form.attr = [];
  607. if (!form.goods_num) {
  608. that.error = '商品库存不得为空';
  609. return false
  610. } else if (form.goods_num < 0) {
  611. that.error = '商品库存不得小于零';
  612. return false
  613. } else {
  614. pass = true;
  615. }
  616. }else {
  617. form.use_attr = 1;
  618. form.goods_num = 0;
  619. if (!form.attr_groups || form.attr_groups.length == 0) {
  620. that.error = '请设置商品规格';
  621. return false
  622. }else {
  623. pass = true
  624. }
  625. }
  626. form.cards = that.goods_card;
  627. form.is_default_services = 1;
  628. form.services = [];
  629. if(!that.confine) {
  630. that.form.confine_count = -1;
  631. }
  632. if(that.is_default_services == 0) {
  633. form.is_default_services = 0;
  634. if (that.beService.length > 0) {
  635. form.services = that.beService;
  636. }
  637. }
  638. form.status = status;
  639. if (that.goods_detail.length > 0) {
  640. form.detail = '';
  641. for(let i in that.goods_detail) {
  642. if(that.goods_detail[i].type == "img") {
  643. form.detail += '<p><img src="' + that.goods_detail[i].pic_url + '"/></p>'
  644. }else if(that.goods_detail[i].type == "line") {
  645. form.detail += '<p><img src="' + that.adminImg.line + '"/></p>'
  646. }else if(that.goods_detail[i].type == "text") {
  647. form.detail += '<p>' + that.goods_detail[i].text + '</p>'
  648. }
  649. }
  650. } else {
  651. that.error = '请设置图文描述';
  652. return false
  653. }
  654. if(!form.mchCats) {
  655. form.mchCats = [];
  656. }
  657. if (that.forehead_integral) {
  658. if (that.forehead_integral > 0) {
  659. form.forehead_integral_type = 1;
  660. form.forehead_integral = that.forehead_integral;
  661. } else {
  662. form.forehead_integral_type = 2;
  663. form.forehead_integral = that.forehead_integral.replace('%', '')
  664. }
  665. }
  666. if (that.give_integral) {
  667. if (that.give_integral > 0) {
  668. form.give_integral_type = 1;
  669. form.give_integral = that.give_integral;
  670. } else {
  671. form.give_integral_type = 2;
  672. form.give_integral = that.give_integral.replace('%', '')
  673. }
  674. }
  675. if(!form.virtual_sales) {
  676. form.virtual_sales = 0;
  677. }
  678. if(!form.cover_pic) {
  679. form.cover_pic = '';
  680. }
  681. if(!form.sort) {
  682. form.sort = 100;
  683. }
  684. if(!form.accumulative) {
  685. form.accumulative = 1;
  686. }
  687. if(!form.member_price) {
  688. form.member_price = {};
  689. }
  690. form.freight_id = that.bePostage.id;
  691. form.freight = that.bePostage;
  692. form.shipping_id = that.beDelivery.id;
  693. form.shipping = that.beDelivery;
  694. if(!form.individual_share) {
  695. form.individual_share = 0;
  696. }
  697. if(!form.is_level) {
  698. form.is_level = 0;
  699. }
  700. if(!form.individual_share) {
  701. form.individual_share = 0;
  702. }
  703. if(!form.video_url) {
  704. form.video_url = '';
  705. }
  706. if (pass) {
  707. that.form = form;
  708. that.form.cats = cats;
  709. if(that.id > 0) {
  710. that.form.id = that.id;
  711. }
  712. if(status == 0) {
  713. that.toSubmit();
  714. }else {
  715. that.beSubmit = true;
  716. }
  717. }
  718. },
  719. close() {
  720. this.error = null;
  721. this.modal = false;
  722. this.beSubmit = false;
  723. },
  724. inputAttr(index) {
  725. this.attr[index].attr_list[0].attr_id = (+index + 2).toString();
  726. },
  727. _longtap: function (img_src,index,e) {
  728. let that = this;
  729. let query = uni.createSelectorQuery();
  730. let nodesRef = query.selectAll(".move-img");
  731. nodesRef.fields({
  732. dataset: true,
  733. rect: true
  734. }, (result) => {
  735. that.elements = result;
  736. }).exec()
  737. // const detail = e.detail;
  738. that.img[index].pic_url = '';
  739. that.x = e.currentTarget.offsetLeft;
  740. that.y = e.currentTarget.offsetTop;
  741. that.imgHidden = false;
  742. that.flag = true;
  743. that.beMove = true;
  744. that.img_src = img_src;
  745. that.beginIndex = index;
  746. },
  747. //触摸结束
  748. touchend: function (e) {
  749. let that = this;
  750. if (!that.flag) {
  751. return;
  752. }
  753. const x = e.changedTouches[0].pageX
  754. const y = e.changedTouches[0].pageY
  755. const list = that.elements;
  756. let data = that.img
  757. const beginIndex = that.beginIndex;
  758. for (let j = 0; j < list.length; j++) {
  759. const item = list[j];
  760. if (x > item.left && x < item.right && y > item.top && y < item.bottom) {
  761. const endIndex = item.dataset.index;
  762. //向后移动
  763. if (beginIndex < endIndex) {
  764. let tem = data[beginIndex];
  765. for (let i = beginIndex; i < endIndex; i++) {
  766. data[i] = data[i + 1]
  767. }
  768. data[endIndex] = tem;
  769. }
  770. //向前移动
  771. if (beginIndex > endIndex) {
  772. let tem = data[beginIndex];
  773. for (let i = beginIndex; i > endIndex; i--) {
  774. data[i] = data[i - 1]
  775. }
  776. data[endIndex] = tem;
  777. }
  778. data[endIndex].pic_url = that.img_src;
  779. that.img = data;
  780. }
  781. }
  782. if (!that.img[beginIndex].pic_url) {
  783. that.img[beginIndex].pic_url = that.img_src;
  784. }
  785. that.imgHidden = true;
  786. that.flag = false;
  787. that.beMove = false;
  788. that.beginIndex = null;
  789. },
  790. //滑动
  791. touchm: function (e) {
  792. if (this.flag) {
  793. const x = e.touches[0].pageX;
  794. const y = e.touches[0].pageY;
  795. this.x = x - 60;
  796. this.y = y - 189;
  797. }
  798. },
  799. cancelService() {
  800. let beService = this.beService;
  801. let service = this.service;
  802. if (beService.length > 0) {
  803. service.forEach(function(res, index) {
  804. res.isChoose = false;
  805. beService.forEach(function(row) {
  806. if (row.id == res.id) {
  807. res.isChoose = true;
  808. }
  809. })
  810. })
  811. } else {
  812. service.forEach(function(res, index) {
  813. res.isChoose = false;
  814. })
  815. }
  816. this.beService = beService;
  817. this.service = service;
  818. this.set_service = false;
  819. this.is_service = false;
  820. setTimeout(v=>{
  821. uni.pageScrollTo({
  822. scrollTop: 45550,
  823. duration: 0
  824. });
  825. },0)
  826. },
  827. submitService() {
  828. let beService = [];
  829. this.service.forEach(function(row) {
  830. if (row.isChoose) {
  831. beService.push(row)
  832. }
  833. })
  834. this.beService = beService;
  835. this.set_service = false;
  836. this.is_service = false;
  837. setTimeout(v=>{
  838. uni.pageScrollTo({
  839. scrollTop: 45550,
  840. duration: 0
  841. });
  842. },0)
  843. },
  844. choose(item) {
  845. let that = this;
  846. that.service.forEach(function(row) {
  847. if (row.id == item.id) {
  848. row.isChoose = !row.isChoose;
  849. that.$forceUpdate();
  850. }
  851. })
  852. },
  853. toGoodsDetail() {
  854. uni.navigateTo({
  855. url: '/pages/app_admin/goods-detail/goods-detail'
  856. })
  857. },
  858. addImg() {
  859. let that = this;
  860. let num = 9 - that.img.length;
  861. uni.chooseImage({
  862. count: num,
  863. sizeType: ['original', 'compressed'],
  864. sourceType: ['album', 'camera'],
  865. success(res) {
  866. // tempFilePath可以作为img标签的src属性显示图片
  867. const tempFilePaths = res.tempFilePaths;
  868. let img = that.img;
  869. tempFilePaths.forEach(function (row, index) {
  870. uni.showLoading({
  871. title: '上传中...'
  872. });
  873. let fileName = '';
  874. // #ifdef MP-BAIDU
  875. fileName = row.substr(row.lastIndexOf('/') + 1);
  876. // #endif
  877. uploadFile({
  878. url: that.$api.upload.file,
  879. filePath: row,
  880. fileType: 'image',
  881. fileName: fileName,
  882. mch_id: 0
  883. }).then(res => {
  884. let imgInfo = null;
  885. // #ifndef MP-BAIDU
  886. imgInfo = JSON.parse(res.data);
  887. // #endif
  888. // #ifdef MP-BAIDU
  889. imgInfo = res.data;
  890. // #endif
  891. if (imgInfo.code === 0) {
  892. img.push({
  893. pic_url: imgInfo.data.url,
  894. id: imgInfo.data.id
  895. })
  896. }
  897. that.img = img;
  898. if (index === tempFilePaths.length - 1) {
  899. uni.hideLoading();
  900. }
  901. }).catch(e => {
  902. if (e && e.errMsg) {
  903. uni.showModal({
  904. title: '错误',
  905. content: e.errMsg,
  906. showCancel: false,
  907. });
  908. }
  909. })
  910. })
  911. }
  912. })
  913. },
  914. del_img(index) {
  915. this.img.splice(index, 1);
  916. },
  917. chooseCat() {
  918. uni.navigateTo({
  919. url: '/pages/app_admin/goods-cat/goods-cat'
  920. })
  921. },
  922. chooseAttr() {
  923. uni.navigateTo({
  924. url: '/pages/app_admin/goods-attr/goods-attr'
  925. })
  926. uni.setStorage({
  927. key: "goods_unit",
  928. data: this.unit
  929. })
  930. },
  931. bindChange(e) {
  932. this.newIndex = e.detail.value[0]
  933. },
  934. toggle(status) {
  935. this.choose_list = [];
  936. this.dialog = false;
  937. this.set_cat = false;
  938. if(this.dialogType == 'postage') {
  939. if (status == 1) {
  940. if (this.set_postage) {
  941. this.bePostage = this.postage[this.newIndex];
  942. }
  943. }else {
  944. this.set_postage = false;
  945. }
  946. }
  947. if(this.dialogType == 'delivery') {
  948. if (status == 1) {
  949. if (this.set_delivery) {
  950. this.beDelivery = this.delivery[this.newIndex];
  951. }
  952. }else {
  953. this.set_delivery = false;
  954. }
  955. }
  956. this.dialogType = '';
  957. },
  958. chooseService() {
  959. let that = this;
  960. if(that.first_service) {
  961. that.$request({
  962. url: that.$api.app_admin.service,
  963. }).then(response=>{
  964. that.$hideLoading();
  965. if(response.code == 0) {
  966. that.service = response.data.list;
  967. if (response.data.list.length == 0) {
  968. that.modal = true;
  969. } else {
  970. that.is_service = true;
  971. }
  972. let beService = [];
  973. for(let row of response.data.list) {
  974. row.isChoose = false
  975. if (row.is_default == 1) {
  976. beService.push(row);
  977. row.isChoose = true
  978. }
  979. }
  980. that.set_service = true;
  981. that.beService = beService;
  982. that.default_service = beService;
  983. that.first_service = false;
  984. }else {
  985. uni.showToast({
  986. title: response.msg,
  987. icon: 'none',
  988. duration: 1000
  989. });
  990. }
  991. }).catch(() => {
  992. that.$hideLoading();
  993. });
  994. }else {
  995. if (that.service.length == 0) {
  996. that.modal = true;
  997. } else {
  998. that.is_service = true;
  999. }
  1000. }
  1001. },
  1002. chooseCard() {
  1003. let that = this;
  1004. that.$request({
  1005. url: that.$api.app_admin.card,
  1006. }).then(response=>{
  1007. that.$hideLoading();
  1008. if(response.code == 0) { true;
  1009. that.card = response.data.list;
  1010. if(response.data.list.length == 0) {
  1011. that.set_card = true;
  1012. that.modal = true;
  1013. }else {
  1014. uni.navigateTo({
  1015. url: '/pages/app_admin/goods-card/goods-card'
  1016. })
  1017. }
  1018. }else {
  1019. uni.showToast({
  1020. title: response.msg,
  1021. icon: 'none',
  1022. duration: 1000
  1023. });
  1024. }
  1025. }).catch(() => {
  1026. that.$hideLoading();
  1027. });
  1028. },
  1029. chooseDelivery() {
  1030. let that = this;
  1031. that.$request({
  1032. url: that.$api.app_admin.delivery_rules,
  1033. }).then(response=>{
  1034. that.$hideLoading();
  1035. if(response.code == 0) {
  1036. if (response.data.list.length == 0) {
  1037. that.set_delivery = true;
  1038. that.modal = true;
  1039. that.delivery = response.data.list;
  1040. } else {
  1041. let arr = [];
  1042. response.data.list.forEach(function (row, index) {
  1043. arr.push(response.data.list[index].id)
  1044. });
  1045. let index = arr.indexOf(that.beDelivery.id);
  1046. if(index > -1) {
  1047. that.deliveryIndex = index;
  1048. that.newIndex = index;
  1049. }else {
  1050. that.beDelivery = ''
  1051. }
  1052. that.set_delivery = true;
  1053. that.dialog = true;
  1054. that.dialogType = 'delivery'
  1055. that.delivery = response.data.list;
  1056. }
  1057. }else {
  1058. uni.showToast({
  1059. title: response.msg,
  1060. icon: 'none',
  1061. duration: 1000
  1062. });
  1063. }
  1064. }).catch(() => {
  1065. that.$hideLoading();
  1066. });
  1067. },
  1068. chooseExpress() {
  1069. let that = this;
  1070. that.$request({
  1071. url: that.$api.app_admin.postage,
  1072. }).then(response=>{
  1073. that.$hideLoading();
  1074. if(response.code == 0) {
  1075. if (response.data.list.length == 0) {
  1076. that.set_postage = true;
  1077. that.modal = true;
  1078. that.postage = response.data.list;
  1079. } else {
  1080. let arr = [];
  1081. response.data.list.forEach(function (row, index) {
  1082. arr.push(response.data.list[index].id)
  1083. });
  1084. let index = arr.indexOf(that.bePostage.id);
  1085. if(index > -1) {
  1086. that.postageIndex = index;
  1087. that.newIndex = index;
  1088. }else {
  1089. that.bePostage = ''
  1090. }
  1091. that.set_postage = true;
  1092. that.dialog = true;
  1093. that.dialogType = 'postage'
  1094. that.postage = response.data.list;
  1095. }
  1096. }else {
  1097. uni.showToast({
  1098. title: response.msg,
  1099. icon: 'none',
  1100. duration: 1000
  1101. });
  1102. }
  1103. }).catch(() => {
  1104. that.$hideLoading();
  1105. });
  1106. },
  1107. getService(id) {
  1108. let that = this;
  1109. this.$request({
  1110. url: this.$api.app_admin.service,
  1111. }).then(response=>{
  1112. that.$hideLoading();
  1113. let { code, data, msg } = response;
  1114. if(code === 0) {
  1115. that.service = data.list;
  1116. for(let i in that.service) {
  1117. that.service[i].isChoose = false;
  1118. }
  1119. if(id > 0) {
  1120. for(let j in that.beService) {
  1121. for(let i in that.service) {
  1122. if(that.service[i].id == that.beService[j].id) {
  1123. that.service[i].isChoose = true;
  1124. that.first_service = false;
  1125. }
  1126. }
  1127. }
  1128. }else {
  1129. that.beService = [];
  1130. data.list.forEach(function(row) {
  1131. row.isChoose = false;
  1132. if (row.is_default == 1) {
  1133. that.beService.push(row);
  1134. row.isChoose = true
  1135. }
  1136. })
  1137. }
  1138. }else {
  1139. uni.showToast({
  1140. title: msg,
  1141. icon: 'none',
  1142. duration: 1000
  1143. });
  1144. }
  1145. }).catch(() => {
  1146. that.$hideLoading();
  1147. });
  1148. },
  1149. getPostage(id) {
  1150. let that = this;
  1151. this.$request({
  1152. url: this.$api.app_admin.postage,
  1153. }).then(response=>{
  1154. that.$hideLoading();
  1155. if(response.code == 0) {
  1156. that.postage = response.data.list;
  1157. if(id > 0) {
  1158. return false;
  1159. }else {
  1160. that.bePostage = '';
  1161. that.bePostage = response.data.list[0];
  1162. }
  1163. }else {
  1164. uni.showToast({
  1165. title: response.msg,
  1166. icon: 'none',
  1167. duration: 1000
  1168. });
  1169. }
  1170. }).catch(() => {
  1171. that.$hideLoading();
  1172. });
  1173. },
  1174. getDelivery(id) {
  1175. let that = this;
  1176. this.$request({
  1177. url: this.$api.app_admin.delivery_rules,
  1178. }).then(response=>{
  1179. that.$hideLoading();
  1180. if(response.code == 0) {
  1181. that.delivery = response.data.list;
  1182. if(id > 0) {
  1183. return false;
  1184. }else {
  1185. that.beDelivery = '';
  1186. that.beDelivery = response.data.list[0];
  1187. }
  1188. }else {
  1189. uni.showToast({
  1190. title: response.msg,
  1191. icon: 'none',
  1192. duration: 1000
  1193. });
  1194. }
  1195. }).catch(() => {
  1196. that.$hideLoading();
  1197. });
  1198. },
  1199. getCard() {
  1200. let that = this;
  1201. this.$request({
  1202. url: this.$api.app_admin.card
  1203. }).then(response=>{
  1204. that.$hideLoading();
  1205. if(response.code == 0) {
  1206. that.card = response.data.list;
  1207. }else {
  1208. uni.showToast({
  1209. title: response.msg,
  1210. icon: 'none',
  1211. duration: 1000
  1212. });
  1213. }
  1214. }).catch(() => {
  1215. that.$hideLoading();
  1216. });
  1217. },
  1218. async getDetail(id) {
  1219. const res = await this.$request({
  1220. url: this.$api.app_admin.goods_edit,
  1221. data: {
  1222. id: id
  1223. }
  1224. });
  1225. let { code, data, msg } = res;
  1226. await this.$hideLoading();
  1227. this.getService(id);
  1228. this.getPostage(id);
  1229. this.getDelivery(id);
  1230. if(code === 0) {
  1231. this.form = data.detail;
  1232. let {
  1233. pic_url, cats, use_attr,
  1234. services, freight, cards,
  1235. confine_count, is_default_services, forehead_integral,
  1236. forehead_integral_type, give_integral, give_integral_type,
  1237. attr_groups, attr, detail, unit, shipping
  1238. } = this.form;
  1239. this.img = pic_url;
  1240. this.cats = cats;
  1241. this.set_attr = use_attr;
  1242. this.beService = services;
  1243. this.bePostage = freight;
  1244. this.beDelivery = shipping;
  1245. this.goods_card = cards;
  1246. this.unit = unit;
  1247. if(confine_count > 0) {
  1248. this.confine = true;
  1249. }
  1250. if(is_default_services == 0) this.is_default_services = false;
  1251. this.forehead_integral = +forehead_integral;
  1252. if(forehead_integral_type == 2) this.forehead_integral = forehead_integral + '%';
  1253. this.give_integral = +give_integral;
  1254. if(give_integral_type == 2) this.give_integral = give_integral + '%';
  1255. if(attr_groups.length > 0 && attr.length > 0) {
  1256. this.attr = true;
  1257. uni.setStorage({
  1258. key: "goods_attr_groups",
  1259. data: attr_groups
  1260. });
  1261. uni.setStorage({
  1262. key: "goods_attr",
  1263. data: attr
  1264. });
  1265. }
  1266. let form_detail = detail.split(/<\/p>|<br\/>|<img /);
  1267. let good_detail = [];
  1268. let para = undefined;
  1269. for(let i in form_detail) {
  1270. form_detail[i] = form_detail[i].replace(/<p>/g, '').replace(/<\/p>/g, '');
  1271. para = {type: ''};
  1272. if(form_detail[i].indexOf('src') > -1) {
  1273. para.type = 'img';
  1274. para.id = '';
  1275. let end = form_detail[i].indexOf('.png') > -1 ? form_detail[i].indexOf('.png') + 4 : form_detail[i].length -1;
  1276. if(form_detail[i].indexOf('.jpg') > -1) {
  1277. end = form_detail[i].indexOf('.jpg') + 4
  1278. }
  1279. if(form_detail[i].indexOf('.jpeg') > -1) {
  1280. end = form_detail[i].indexOf('.jpeg') + 5
  1281. }
  1282. if(form_detail[i].indexOf('.gif') > -1) {
  1283. end = form_detail[i].indexOf('.gif') + 4
  1284. }
  1285. para.pic_url = form_detail[i].slice(form_detail[i].indexOf('http'), end);
  1286. }else {
  1287. para.type = 'text';
  1288. para.text = form_detail[i];
  1289. }
  1290. good_detail[i] = para;
  1291. }
  1292. for(let i in good_detail) {
  1293. if(good_detail[i].text === '') {
  1294. good_detail.splice(i,1);
  1295. }
  1296. }
  1297. this.goods_detail = good_detail;
  1298. uni.setStorage({
  1299. key: "goods_card",
  1300. data: cards
  1301. });
  1302. uni.setStorage({
  1303. key: "goods_cat",
  1304. data: this.cats
  1305. });
  1306. uni.setStorage({
  1307. key: "goods_detail",
  1308. data: good_detail
  1309. })
  1310. }else {
  1311. uni.showToast({
  1312. title: msg,
  1313. icon: 'none',
  1314. duration: 1000
  1315. });
  1316. }
  1317. },
  1318. // 选卡密列表
  1319. chooseECard() {
  1320. if (this.id !== 0) return;
  1321. this.$request({
  1322. url: this.$api.app_admin.ecard_api_url + this.ecard_api_url,
  1323. }).then(res => {
  1324. let { code, data, msg } = res;
  1325. this.$hideLoading();
  1326. if(code === 0) {
  1327. if (data.length === 0) {
  1328. this.ecard_set_postage = true;
  1329. this.ecard_postage = data;
  1330. } else {
  1331. let arr = [];
  1332. data.forEach((row, index) => {
  1333. arr.push(data[index].id);
  1334. });
  1335. let index = arr.indexOf(this.form.plugin_data.ecard.ecard_id);
  1336. if(index > -1) {
  1337. this.ecard_postageIndex = index;
  1338. this.newIndex = index;
  1339. }else {
  1340. this.form.plugin_data.ecard = {
  1341. ecard_id: 0,
  1342. name: ''
  1343. };
  1344. }
  1345. this.ecard_set_postage = true;
  1346. this.ecard_dialog = true;
  1347. this.ecard_postage = data;
  1348. }
  1349. }else {
  1350. uni.showToast({
  1351. title: msg,
  1352. icon: 'none',
  1353. duration: 1000
  1354. });
  1355. }
  1356. }).catch(() => {
  1357. this.$hideLoading();
  1358. });
  1359. },
  1360. typeChange(e) {
  1361. if (this.id === 0) {
  1362. this.form.type = e.target.value;
  1363. }
  1364. },
  1365. async getGoodsConfig() {
  1366. const e = await this.$request({
  1367. url: this.$api.app_admin.goods_config,
  1368. });
  1369. if (e.code === 0) {
  1370. this.is_ecard = e.data.is_ecard;
  1371. this.ecard_api_url = e.data.ecard_api_url;
  1372. }
  1373. },
  1374. ecardToggle(status) {
  1375. this.ecard_dialog = false;
  1376. if (status == 1) {
  1377. if (this.ecard_set_postage) {
  1378. this.form.plugin_data.ecard = {
  1379. ecard_id: this.ecard_postage[this.newIndex].id,
  1380. name: this.ecard_postage[this.newIndex].name,
  1381. }
  1382. }
  1383. }else {
  1384. this.ecard_set_postage = false;
  1385. }
  1386. },
  1387. },
  1388. onLoad(options) {
  1389. let that = this;
  1390. uni.getSystemInfo({
  1391. success: function (res) {
  1392. that.windowHeight = res.windowHeight;
  1393. if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
  1394. that.iphone_x = true;
  1395. }
  1396. }
  1397. });
  1398. uni.getSystemInfo({
  1399. success: function (res) {
  1400. let clientHeight = res.windowHeight;
  1401. let clientWidth = res.windowWidth;
  1402. let ratio = 750 / clientWidth;
  1403. that.height = clientHeight * ratio;
  1404. }
  1405. });
  1406. that.getCard();
  1407. that.getGoodsConfig();
  1408. uni.removeStorage({
  1409. key: 'goods_card',
  1410. success() {
  1411. that.goods_card = [];
  1412. }
  1413. });
  1414. uni.removeStorage({
  1415. key: 'goods_cat'
  1416. });
  1417. uni.removeStorage({
  1418. key: 'goods_unit'
  1419. });
  1420. uni.removeStorage({
  1421. key: 'goods_attr_groups'
  1422. });
  1423. uni.removeStorage({
  1424. key: 'goods_attr'
  1425. });
  1426. uni.removeStorage({
  1427. key: 'temp_attr'
  1428. });
  1429. uni.removeStorage({
  1430. key: 'temp_attr_info'
  1431. });
  1432. uni.removeStorage({
  1433. key: 'goods_detail',
  1434. success() {
  1435. that.goods_detail = [];
  1436. }
  1437. });
  1438. if(options.id > 0) {
  1439. that.$showLoading({
  1440. type: 'global',
  1441. text: '加载中...'
  1442. });
  1443. that.id = options.id;
  1444. setTimeout(()=>{
  1445. uni.setNavigationBarTitle({
  1446. title: '编辑商品',
  1447. });
  1448. that.getDetail(options.id);
  1449. },500);
  1450. }else {
  1451. that.getService();
  1452. that.getPostage();
  1453. that.getDelivery();
  1454. }
  1455. },
  1456. onShow() {
  1457. let that = this;
  1458. uni.getStorage({
  1459. key: 'goods_card',
  1460. success(res) {
  1461. that.goods_card = res.data;
  1462. }
  1463. });
  1464. uni.getStorage({
  1465. key: 'goods_cat',
  1466. success(res) {
  1467. that.cats = res.data;
  1468. }
  1469. });
  1470. uni.getStorage({
  1471. key: 'goods_detail',
  1472. success(res) {
  1473. that.goods_detail = res.data;
  1474. }
  1475. });
  1476. uni.getStorage({
  1477. key: 'goods_attr_groups',
  1478. success(res) {
  1479. that.form.attr_groups = res.data;
  1480. that.attr = true;
  1481. }
  1482. });
  1483. uni.getStorage({
  1484. key: 'goods_attr',
  1485. success(res) {
  1486. that.form.attr = res.data;
  1487. }
  1488. });
  1489. uni.removeStorage({
  1490. key: 'temp_attr'
  1491. });
  1492. uni.removeStorage({
  1493. key: 'temp_attr_info'
  1494. });
  1495. },
  1496. watch: {
  1497. 'form.type' : {
  1498. handler(data) {
  1499. if (data === 'goods') {
  1500. this.form.plugin_data.ecard.ecard_id = 0;
  1501. this.form.plugin_data.ecard.name = '';
  1502. }
  1503. },
  1504. deep: true
  1505. }
  1506. }
  1507. }
  1508. </script>
  1509. <style scoped lang="scss">
  1510. .title {
  1511. font-size: #{28rpx};
  1512. color: #999;
  1513. margin: #{30rpx} #{24rpx} #{13rpx};
  1514. }
  1515. .goods-img {
  1516. background-color: #fff;
  1517. padding: #{32rpx} #{24rpx};
  1518. }
  1519. .goods-list {
  1520. margin-top: #{8rpx};
  1521. margin-left: #{-24rpx};
  1522. }
  1523. .goods-item {
  1524. position: relative;
  1525. margin-left: #{24rpx};
  1526. margin-top: #{24rpx};
  1527. height: #{218rpx};
  1528. width: #{218rpx};
  1529. }
  1530. .label {
  1531. font-size: #{28rpx};
  1532. color: #999;
  1533. }
  1534. .goods-cover {
  1535. height: #{218rpx};
  1536. width: #{218rpx};
  1537. }
  1538. .del-btn {
  1539. height: #{40rpx};
  1540. width: #{40rpx};
  1541. position: absolute;
  1542. right: #{-8rpx};
  1543. top: #{-16rpx};
  1544. }
  1545. .main-img {
  1546. height: #{40rpx};
  1547. line-height: #{40rpx};
  1548. width: #{218rpx};
  1549. text-align: center;
  1550. font-size: #{24rpx};
  1551. color: #fff;
  1552. background-color: rgba(68, 109, 253, 0.5);
  1553. position: absolute;
  1554. bottom: 0;
  1555. left: 0;
  1556. }
  1557. .add-goods-img {
  1558. background-color: #f4f5f9;
  1559. position: relative;
  1560. margin-left: #{24rpx};
  1561. margin-top: #{24rpx};
  1562. height: #{218rpx};
  1563. width: #{218rpx};
  1564. font-size: #{24rpx};
  1565. color: #999;
  1566. z-index: 10;
  1567. text-align: center;
  1568. }
  1569. .add-goods-img image {
  1570. height: #{40rpx};
  1571. width: #{40rpx};
  1572. margin: #{70rpx} auto #{10rpx};
  1573. }
  1574. .goods-info {
  1575. background-color: #fff;
  1576. padding: 0 #{24rpx};
  1577. .info-item:first-of-type {
  1578. border-top: 0;
  1579. }
  1580. .info-item.goods-name {
  1581. border-top: #{1rpx} solid #e2e2e2;
  1582. }
  1583. }
  1584. .form-label {
  1585. width: #{176rpx};
  1586. }
  1587. .info-item {
  1588. border-top: #{1rpx} solid #e2e2e2;
  1589. height: #{88rpx};
  1590. line-height: #{88rpx};
  1591. font-size: #{28rpx};
  1592. color: #353535;
  1593. }
  1594. view.input {
  1595. height: #{80rpx};
  1596. line-height: #{80rpx};
  1597. white-space: nowrap;
  1598. overflow: auto;
  1599. }
  1600. view.input.placeholder {
  1601. color: #cdcdcd;
  1602. }
  1603. .input {
  1604. width: #{476rpx};
  1605. background-color: #fff;
  1606. padding-left: #{25rpx};
  1607. font-size: #{28rpx};
  1608. }
  1609. .input.unit {
  1610. width: #{396rpx};
  1611. }
  1612. .unit-width {
  1613. width: #{112rpx};
  1614. text-align: right;
  1615. }
  1616. .cat-info {
  1617. width: #{526rpx};
  1618. color: #666;
  1619. }
  1620. .to-more {
  1621. height: #{24rpx};
  1622. width: #{12rpx};
  1623. margin-left: #{10rpx};
  1624. }
  1625. .price-input {
  1626. position: relative;
  1627. color: #666;
  1628. height: #{88rpx};
  1629. }
  1630. .money {
  1631. position: absolute;
  1632. height: #{88rpx};
  1633. line-height: #{88rpx};
  1634. width: #{20rpx};
  1635. left: 0;
  1636. top: 0;
  1637. }
  1638. .attr-info {
  1639. background-color: #fff;
  1640. padding: 0 #{24rpx};
  1641. margin-top: #{20rpx};
  1642. }
  1643. .attr-input {
  1644. width: #{638rpx};
  1645. }
  1646. .attr-input .input {
  1647. color: #666;
  1648. width: #{412rpx};
  1649. }
  1650. .attr-input .input.unit {
  1651. width: #{330rpx};
  1652. }
  1653. .express-setting {
  1654. height: #{136rpx};
  1655. padding: #{16rpx} 0 #{20rpx};
  1656. border-top: #{1rpx} solid #e2e2e2;
  1657. }
  1658. .express-input {
  1659. position: relative;
  1660. .input-item {
  1661. font-size: #{28rpx};
  1662. color: #353535;
  1663. .input {
  1664. width: #{650rpx};
  1665. }
  1666. }
  1667. }
  1668. .express-input .input {
  1669. width: #{702rpx};
  1670. padding-left: #{216rpx};
  1671. }
  1672. .express-input .integral {
  1673. position: absolute;
  1674. left: 0;
  1675. z-index: 2;
  1676. }
  1677. .express-etc {
  1678. color: #999;
  1679. font-size: #{24rpx};
  1680. margin-top: #{16rpx};
  1681. }
  1682. .form-button {
  1683. width: #{656rpx};
  1684. margin: 0 auto;
  1685. }
  1686. .save {
  1687. height: #{80rpx};
  1688. line-height: #{80rpx};
  1689. text-align: center;
  1690. width: #{300rpx};
  1691. margin: #{80rpx} 0;
  1692. font-size: #{28rpx};
  1693. color: #446dfd;
  1694. border: #{2rpx} solid #446dfd;
  1695. background-color: #FFFFFF;
  1696. border-radius: #{40rpx};
  1697. }
  1698. .send {
  1699. height: #{80rpx};
  1700. line-height: #{80rpx};
  1701. text-align: center;
  1702. width: #{300rpx};
  1703. margin: #{80rpx} #{24rpx};
  1704. font-size: #{28rpx};
  1705. color: #fff;
  1706. background-color: #446dfd;
  1707. border-radius: #{40rpx};
  1708. }
  1709. .dialog {
  1710. position: fixed;
  1711. height: 100%;
  1712. width: 100%;
  1713. bottom: 0;
  1714. left: 0;
  1715. z-index: 10;
  1716. background-color: rgba(0, 0, 0, .3);
  1717. }
  1718. .dialog.iphone_x .picker-list{
  1719. padding-bottom: #{50rpx};
  1720. }
  1721. .picker {
  1722. width: 100%;
  1723. height: #{440rpx};
  1724. color: #999999;
  1725. }
  1726. .dialog.iphone_x .picker{
  1727. height:#{490rpx};
  1728. }
  1729. .picker-list {
  1730. background-color: #fff;
  1731. padding-top: #{20rpx};
  1732. position: fixed;
  1733. bottom: 0;
  1734. left: 0;
  1735. width: 100%;
  1736. }
  1737. .picker-header {
  1738. padding: 0 #{24rpx};
  1739. color: #446dfd;
  1740. font-size: #{32rpx};
  1741. }
  1742. .is_cat {
  1743. padding: #{50rpx} 0 0 #{24rpx};
  1744. color: #666666;
  1745. font-size: #{28rpx};
  1746. border-bottom: #{1rpx} solid #e2e2e2;
  1747. }
  1748. .is_cat text {
  1749. margin-right: #{48rpx};
  1750. display: inline-block;
  1751. max-width: #{130rpx};
  1752. white-space: nowrap;
  1753. overflow: hidden;
  1754. text-overflow: ellipsis;
  1755. }
  1756. .is_cat text:last-of-type {
  1757. padding-bottom: #{24rpx};
  1758. color: #446dfd;
  1759. border-bottom: #{2rpx} solid #446dfd;
  1760. }
  1761. .type-list {
  1762. max-height: #{400rpx};
  1763. overflow: auto;
  1764. }
  1765. .type-choose {
  1766. padding: 0 #{24rpx} 0 #{72rpx};
  1767. line-height: #{36rpx};
  1768. color: #353535;
  1769. font-size: #{32rpx};
  1770. text-align: left;
  1771. margin: #{35rpx} 0 #{50rpx};
  1772. }
  1773. .type-choose .active {
  1774. color: #446dfd;
  1775. }
  1776. .active-status {
  1777. width: #{36rpx};
  1778. height: #{36rpx};
  1779. display: block;
  1780. margin-right: #{24rpx};
  1781. flex-shrink: 0;
  1782. }
  1783. .attr-btn-item {
  1784. padding-left: #{88rpx};
  1785. background-color: #fff;
  1786. }
  1787. .dialog-item {
  1788. padding-top: #{20rpx};
  1789. position: fixed;
  1790. top: 25%;
  1791. left: 0;
  1792. right: 0;
  1793. margin: 0 auto;
  1794. width: #{620rpx};
  1795. border-radius: #{16rpx};
  1796. background-color: #fff;
  1797. }
  1798. .btn-area {
  1799. height: #{88rpx};
  1800. position: relative;
  1801. border-top: #{1rpx} solid #e2e2e2;
  1802. }
  1803. .btn-area .line {
  1804. height: #{32rpx};
  1805. width: #{1rpx};
  1806. background-color: #e2e2e2;
  1807. position: absolute;
  1808. top: #{28rpx};
  1809. left: 0;
  1810. right: 0;
  1811. margin: 0 auto;
  1812. }
  1813. .submit-btn {
  1814. height: #{88rpx};
  1815. line-height: #{88rpx};
  1816. font-size: #{32rpx};
  1817. color: #666;
  1818. width: #{310rpx};
  1819. text-align: center;
  1820. }
  1821. .submit-btn.be-submit {
  1822. color: #446dfd;
  1823. }
  1824. .dialog-title {
  1825. text-align: center;
  1826. margin: #{15rpx} 0 #{50rpx};
  1827. }
  1828. .img-border {
  1829. height: #{250rpx};
  1830. width: #{250rpx};
  1831. margin-top: #{-16rpx};
  1832. margin-left: #{-16rpx};
  1833. }
  1834. .screen {
  1835. height: 100%;
  1836. overflow: hidden;
  1837. }
  1838. .error-info {
  1839. text-align: center;
  1840. margin: #{50rpx};
  1841. }
  1842. .submit-info {
  1843. text-align:center;
  1844. margin-bottom: #{60rpx};
  1845. }
  1846. .picker-text {
  1847. line-height: #{88rpx};
  1848. color: #446dfd;
  1849. font-size: #{32rpx};
  1850. padding-left: #{24rpx};
  1851. }
  1852. .picker-text.sure-color {
  1853. color: #446dfd;
  1854. }
  1855. .picker-text.cardinal-color {
  1856. color: #999999;
  1857. }
  1858. .picker-text.even-color {
  1859. color: #cdcdcd;
  1860. }
  1861. .integral {
  1862. font-size: #{28rpx};
  1863. color: #353535;
  1864. }
  1865. .integral-info .express-setting {
  1866. height: #{164rpx};
  1867. }
  1868. .integral-info .express-setting:first-of-type {
  1869. border-top:0
  1870. }
  1871. .label-info {
  1872. font-size: #{24rpx};
  1873. color: #999999;
  1874. }
  1875. .goods-type {
  1876. background-color: #fff;
  1877. padding: 0 #{24rpx};
  1878. margin-bottom: #{18upx};
  1879. .type {
  1880. border-top: 0;
  1881. }
  1882. .select {
  1883. width: #{408upx};
  1884. }
  1885. .select-label {
  1886. font-size: #{26upx};
  1887. margin-left: #{23upx};
  1888. }
  1889. }
  1890. .service-text {
  1891. width: 500rpx;
  1892. text-align: right;
  1893. overflow: hidden;
  1894. white-space: nowrap;
  1895. text-overflow: ellipsis;
  1896. }
  1897. </style>