add-goods.vue 79 KB

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